package v3.object;

import galaxy.obj.Point;
import text.TextUtil;

public class Screen
{
	public String[][] screen;
	public int rows;
	public int cols;
	static final int ORR = 0;
	static final int VER = 1;
	double rad45 = Math.toRadians(45);

	public Screen(int rows, int cols)
	{
		this.rows = rows;
		this.cols = cols;
		screen = new String[rows][cols];
		erease();
	}

	public void fill(String s)
	{	
		erease();
		int step=1;
		if(s.length()>1)
			step=s.length();
		for (int i = 0; i < rows; i++)
		{
			String[] r = screen[i];
			for (int j = 0; j < cols; j=j+step)
			{
				r[j] = s;
			}
		}
	}

	public void erease()
	{
		for (int i = 0; i < rows; i++)
		{
			String[] r = screen[i];
			for (int j = 0; j < cols; j++)
			{
				r[j] = "";
			}
		}
	}
	public void printAt(int row_y, int col_x, String s)
	{
		printAt(row_y, col_x, s, ORR);
	}

	private void printAt(int row, int col, String s, int direction)
	{

		for (int i = 0; i < s.length(); i++)
		{
			int r = row;
			int c = col + i;
			if (direction == VER)
			{
				r = row + i;
				c = col;
			}
			if (r > rows - 1 || c > cols - 1)
				continue;
			screen[r][c] = s.substring(i, i + 1);

		}

	}

	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < rows; i++)
		{
			String[] r = screen[i];
			for (int j = 0; j < cols; j++)
			{
				sb.append(r[j]);
			}
			sb.append("\n");
		}
		return sb.toString();
	}

	public static void main(String[] args)
	{
		Screen s = new Screen(10, 10);
		s.fill(".");
		s.drawLine(new Point(10, 0), 2, "*");
		System.out.println(s);

	}

	public void printAt(double row, double col, String s)
	{
		printAt((int) row, (int) col, s);

	}

	public void drawLine(Point a, int cursor, String str)
	{
		for (int i = 1; i < 4; i++)
		{
			Point b = STcfg.getNewPosition(a, cursor, i);
			//Point p = new Point(ship.getPositionManover().getX()+3, ship.getPositionManover().getY()*2+4);
			//System.out.println("i=" + i+"\tp="+b);
			int x = (int) (b.getY() + 3);
			int y = (int) (b.getX() * 2 + 4);
			printAt(x,y, str);
		}
	}

	public void printAt(int row, int col, StringBuilder sb)
	{
		printAt(row, col, sb.toString());
	}

}
